<?php
$title="修改订单";
$css="modifyorder.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$discount_per_level=0.05;
$oid=$_GET["id"];
$page=$_GET["page"];
$updown=$_GET["updown"];
$meta=$_GET["meta"];
$AnOrder=$db->get_oid_order($oid);

$state=$_POST["state"];
if(!isset($state))
{
	$state=$AnOrder["state"];
}
$count=$_POST["count"];
if(!isset($count))
{
	$count=$AnOrder["count"];
}
if(isset($_POST["count"]))//说明管理员按了保存修改按钮
{
	$thisProduct=$db->get_pid_product($AnOrder["pid"]);
	$thisUser=$db->get_uid_info($AnOrder["uid"]);
	?>
	<script language="JavaScript">	
		var page='<?php print_r($page)?>';
		var updown='<?php print_r($updown)?>';
		var meta='<?php print_r($meta)?>';
		var id='<?php print_r($oid)?>';
	</script>
	<?php 
	if($count>($thisProduct[0]["count"]+$AnOrder["count"]))
	{
		?>
		<script language="JavaScript">	
		alert("库存不足");
		window.location.href="modifyorder.php?page="+page+"&updown="+updown+"&meta="+meta+"&id="+id;
		</script>
	<?php 
	 	//header("Location:modifyorder.php?page=$page&updown=$updown&meta=$meta&id=$oid");
	 	//exit();
	}
	else {
		
		$should=$count*$thisProduct[0]["act_price"]*(1-$discount_per_level*$thisUser[0]["level"]);
		$should=number_format($should,1,'.','');
		//$should=number_format($should,2,'.','');
		$db->saveOrder($oid,$AnOrder["pid"],$count,$should,$state,$AnOrder["count"]);
		?>
	<script language="JavaScript">
	window.location.href="orderList.php?page="+page+"&updown="+updown+"&meta="+meta;
	</script>
	<?php 
		//header("Location:orderList.php?page=$page&updown=$updown&meta=$meta");
	}

}
	?>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">订单详细信息</p>
				<form action="modifyorder.php?meta=<?php echo $meta;?>&updown=<?php echo $updown;?>&page=<?php echo $page;?>&id=<?php echo $AnOrder["oid"];?>" method="post">
					<table >
						<tr>
							<th class="t1" >
							</th>
							<th class="t2">
							</th>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>订单号:</b>
							</td >
							<td style="text-align: left;"><?php echo $AnOrder["oid"];?></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>商品名称:</b>
							</td>
							<td style="text-align: left;"><?php echo $AnOrder["p_name"];?></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>单价:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;text-align: left;">￥</label><?php echo number_format($AnOrder["price"],2,'.','');?></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>数量:</b>
							</td>
							<td style="text-align: left;"><input type="text" style="width:60px;" name="count"  value="<?php echo $AnOrder["count"];?>"/></td>
						</tr>
						<tr>
							<td style="text-align: right;">
							<b>应付款:</b>
							</td>
							<td style="text-align: left;"><label style="color:orange;">￥</label><?php echo number_format($AnOrder["should_pay"],2,'.','');?></td>
						</tr>
						<tr>
							<td style="text-align: right;" rowspan="2">
							<b>订单状态:</b>
							</td>
							<td style="text-align: left;">
								<input type="radio" name="state" value="1" <?php if($AnOrder["state"]==1){echo 'checked="checked"';}?>/>
								<label>未付款</label>
								<input type="radio" name="state" value="2" <?php if($AnOrder["state"]==2){echo 'checked="checked"';}?>/>
								<label>已付款</label>
							</td>
						</tr>	
						<tr>
						<td style="text-align: left;">
								<input type="radio" name="state" value="3" <?php if($AnOrder["state"]==3){echo 'checked="checked"';}?>/>
								<label>已发货</label>
								<input type="radio" name="state" value="4" <?php if($AnOrder["state"]==4){echo 'checked="checked"';}?>/>
								<label>已收货</label>
						</td>
						</tr>				
						</table>
						<p><input type="submit" value="保存修改" />
						<input type="button" value="返回列表" onclick="window.location.href='orderList.php?page=<?php echo $page;?>&updown=<?php echo $updown;?>&meta=<?php echo $meta;?>'"/>
						</p>
				</form>
			</div>
<?php 
include_once 'common/AdminTail.php';
?>